package com.wavehi.native_component.config;

import com.wavehi.native_component.web.filter.MyFilter;
import com.wavehi.native_component.web.listener.MyListener;
import com.wavehi.native_component.web.servlet.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.ServletRegistration;

/**
 * @Author WaveHi
 * @Date 15/11/2021 下午 10:26
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
@Configuration
public class MyConfig {

    @Bean
    public ServletRegistrationBean<MyServlet> myServlet() {
        MyServlet myServlet = new MyServlet();
        ServletRegistrationBean<MyServlet> mrb =
                new ServletRegistrationBean<>(myServlet, "/myServlet");
        mrb.addUrlMappings("/my");
        return mrb;
    }

    @Bean
    public FilterRegistrationBean<MyFilter> myFilter() {
        MyFilter myFilter = new MyFilter();
        FilterRegistrationBean<MyFilter> frb =
                new FilterRegistrationBean(myFilter, myServlet());
        frb.addUrlPatterns("/wow");
        return frb;
    }

    @Bean
    public ServletListenerRegistrationBean<MyListener> myListener() {
        MyListener myListener = new MyListener();
        ServletListenerRegistrationBean<MyListener> lslr =
                new ServletListenerRegistrationBean<>(myListener);
        return lslr;
    }
}
